package com.example.helloworld;

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

public class HelloWorldMidlet extends MIDlet implements CommandListener {

    public HelloWorldMidlet() {
    }
    // Display
    private Display display;
    // Main form
    private Form form;
    private Form form2;
    private Form form3;
    // For the message
    private StringItem stringItem;
    private StringItem help;
    private StringItem  ba3boos;
    // For the exit command
    private Command exitCommand;
    private Command backCommand;
    private Command helpCommand;
    private Command ba3boosCommand;

    public void commandAction(Command command, Displayable displayable) {
        if (displayable == form) {
            if (command == exitCommand) {
                exitMIDlet();
            }
            if (command == helpCommand) {
                helpMIDlet();
            }
            if (command == ba3boosCommand){
                ba3boosMIDlet();
            }
        }
        if (displayable == form2){
            if (command == backCommand){
                backMIDlet();
            }
        }

    }

    public void startApp() {
        // Create form
        stringItem = new StringItem("Hello", "Hello World!");
        form = new Form(null, new Item[] {stringItem});
        helpCommand = new Command("Help", Command.HELP, 1);
        form.addCommand(helpCommand);
        ba3boosCommand = new Command("ba3boos", Command.BACK,2 );
        form.addCommand(ba3boosCommand);
        exitCommand = new Command("Exit", Command.EXIT, 3);
        form.addCommand(exitCommand);
        form.setCommandListener(this);

        // Get display for drawning
        display = Display.getDisplay(this);
        display.setCurrent(form);
        help = new StringItem("Help", "This is the help!");
        form2 = new Form(null, new Item[]{help});
        backCommand = new Command("Back", Command.BACK,0);
        form2.addCommand(backCommand);
        form2.setCommandListener(this);
        ba3boos = new StringItem("ba3boos", "this is a big ba3boos for hafez!");
        form3 = new Form (null, new Item[]{ba3boos});


    }

    // Your MIDlet should not call pauseApp(), only system will call this life-cycle method
    public void pauseApp() {
    }

    // Your MIDlet should not call destroyApp(), only system will call this life-cycle method
    public void destroyApp(boolean unconditional) {
    }

    public void exitMIDlet() {
        display.setCurrent(null);
        notifyDestroyed();
    }
    public void helpMIDlet(){
        display.setCurrent(form2);

    }
    public void backMIDlet(){
        display.setCurrent(form);
    }
    public void ba3boosMIDlet(){
        display.setCurrent(form3);
    }

}